package com.daka.controller;

import com.daka.entity.Team;
import com.daka.enumerate.StatusCode;
import com.daka.service.OrderService;
import com.daka.service.TeamService;
import com.daka.vo.DataResponseVo;
import com.daka.vo.response.StatisticsSimpVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * Created by yangx
 * CreateTime: 2016/12/12 17:08
 */

@Controller
@RequestMapping("/statistics")
@Slf4j
public class StatisticsController {

    @Resource
    private TeamService teamService;

    @Resource
    private OrderService orderService;

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/findAllMoney", consumes = "application/json")
    public DataResponseVo<StatisticsSimpVo> findList() {
        List<Team> teamList = teamService.findList();
        BigDecimal total = BigDecimal.valueOf(0);
        for (Team team : teamList){
            total = total.add(team.getTotalMoney());
        }

        Integer number = orderService.findAllCount();

        return new DataResponseVo<>(StatusCode.OK.getCode(),StatusCode.OK.getMessage(),StatisticsSimpVo.build(total,number));
    }
}
